package com.example.wemedia.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.wemedia.dao.WmUserDao;
import com.example.wemedia.service.WmUserService;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.common.enums.AppHttpCodeEnum;
import com.usian.model.media.dtos.WmApUserDto;
import com.usian.model.media.pojos.WmUser;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class WmUserServiceImpl implements WmUserService {

    @Autowired
    private WmUserDao wmUserDao;


    /**
     * 新增自媒体用户
     *
     * @param wmApUserDto
     * @return
     */
    @Override
    public ResponseResult addWmUser(WmApUserDto wmApUserDto) {
        WmUser wmUser = new WmUser();
        wmUser.setType(0);
        wmUser.setCreatedTime(new Date());
        BeanUtils.copyProperties(wmApUserDto, wmUser);
        int i = wmUserDao.insert(wmUser);
        if (i > 0) {
             return ResponseResult.okResult(wmUser.getId());
        }
        return ResponseResult.errorResult(AppHttpCodeEnum.FAIL);
    }

    @Override
    public List<WmUser> findWmUserByName(String name) {
        LambdaQueryWrapper<WmUser> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(WmUser::getName, name);
        return wmUserDao.selectList(lambdaQueryWrapper);
    }
}
